package gtkwire.widget;

import gtkwire.*;

/**
*A widget that reports messages of minor importance to the user. Status bars in GTK+ maintain a stack of messages. The message at the top of the each bar's stack is the one that will currently be displayed.
*/
public class GtkStatusbar extends GtkHBox
{
	private Object createFlag = null;//used to stop GtkHBox from creating native widget.
	private int contextID = -99999;
	private final String contextText = "context";

        public GtkStatusbar()
        {
		super();
		this.widgetType = WT_GtkStatusbar;
		createFlag = new Object();
		gtkCreate();
		createFlag = null;
        }

        public GtkStatusbar( String name, GladeKey key )
        {
		super( name, key );
		this.widgetType = WT_GtkStatusbar;
        }

	protected String[] getCreateData()
	{
		if( createFlag == null ) return null;
		return emptyMsg;
	}

	/**
	*Pushes a new message onto a statusbar's stack.
	*/
	public int push( String text )
	{
		if( contextID == -99999 )
		{
			GTKWireMessage answer2 = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.GET_CONTEXT_ID, contextText );
			contextID = ((Integer) answer2.getMessageObject()).intValue();
			System.out.println("contextID:" + contextID );
		}
		String[] msg = new String[2];
		msg[0] = text;
		msg[1] = (new Integer(contextID)).toString();
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.STACK_OP_CR, msg );
		return ((Integer) answer.getMessageObject()).intValue();
	}

	/**
	*Removes the first message in the GtkStatusBar's stack.
	*/
	public void pop()
	{
		if( contextID == -99999 ) return;

		String[] msg = new String[3];
		msg[0] = "pop";
		msg[1] = "1";//dummy value
		msg[2] = (new Integer(contextID)).toString();

		app().sendCommand( name, GTKWireCommandRequest.STACK_OP, msg);
	}
	
	/**
	*Forces the removal of a message from a statusbar's stack. Message id provided when meaasage id pushed into stack.
	*/
	public void remove( int messageID )
	{
		if( contextID == -99999 ) return;

		String[] msg = new String[3];
		msg[0] = "remove";
		msg[1] = (new Integer(messageID)).toString();
		msg[2] = (new Integer(contextID)).toString();

		app().sendCommand( name, GTKWireCommandRequest.STACK_OP, msg);
	}

}//end class